
#ifndef __HAL_EXP_VALVE_H__
#define __HAL_EXP_VALVE_H__

#include <stdint.h>
#include "stm32f103xe.h"
#ifdef __cplusplus
 extern "C" {
#endif


/****************Include  Section  End*****************************************************/

/****************Marco  Definition Section Begin*******************************************/
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 
#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr)) 
#define GPIOD_ODR_Addr    (GPIOD_BASE+12) //0x4001140C 
#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum)) 
#define PDout(n)   BIT_ADDR(GPIOD_ODR_Addr,n)  //��� 

#define PULSEA PDout(0)
#define PULSEB PDout(1)
#define PULSENA PDout(2)
#define PULSENB PDout(3)


#define	VALVEIDLE		0
#define VALVESTOP 		1
#define VALVECLOSEING 		2
#define	VALVECLOSEPAUSE		3
#define VALVEOPENING 		4
#define	VALVEOPENPAUSE		5
#define VALVEOPENSTART		6
#define	VALVECLOSESTART		7
#define	VALVEREVERSECLOSE	8
#define	VALVEREVERSEOPEN	9


#define		INVERTER_FREQ				0
#define		INVERTER_TRIP				1
#define		INVERTER_FREQSTATE		2
#define		INVERTER_VOLT1			3
#define		INVERTER_CURRENT1			4
#define		INVERTER_VOLT2			5
#define		INVERTER_CURRENT2			6
#define		INVERTER_TEMP1			7
#define		INVERTER_TEMP2			8
#define		INVERTER_TEMP3			9
#define		INVERTER_STATE			10


/****************Marco  Definition Section End*********************************************/
/****************Struct Definition Section Begin*********************************************/
typedef struct
{
	u16 Update;
	u16 SetFreq;
	u16 Freq;
	s16 Adjust;     ///��Ҫ�����Ĳ���
	u8 Operate;
	u16 Step;		///��ǰ����
	u8 PulseA;
	u8 PulseNA;
	u8 PulseB;
	u8 PulseNB;
	u8 Pulse;
  u8 InitialState;

}VALVE;                                        


/****************Struct Definition Section End*********************************************/

/****************Global Variation Definition Section Begin****************************************/

     
/****************Global Variation Definition Section End******************************************/

/****************Externel Function Declaration Section Begin*************************************/

//
extern void AdjustValve(s16 Step);
extern void AdjustValveAbs(s16 AbsStep);
extern void VavleInitClose(void);
extern u8 Valve_Control(void);
extern u16 ValveGetSteps(void);
extern void ValveInitial(void);
extern void InverterSetHz(u8 Hz);
extern u8 InverterGetHz(void);
extern u8 InverterGetPackData(void);
extern u8 GetInvertData(u8 index);
extern void ValveSetFreq (u8 freq);
extern u8 ValveGetFreq (void);
extern void ValveSetAdjustPercent(u16 percent);
extern s16 ValveGetAdjustPercent(void);
extern u8 ValveGetStepPercent(void);
extern u16 ValveGetSteps(void);

extern u16 ValveGetPercent(void);

/****************Externel Function Declaration Section End*************************************/

#endif


